#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;
using db = double;
using tl = tuple < int, int, int >;

ll read() {
    ll x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int mod = 1e9 + 7;
const int inv2 = (mod + 1) >> 1;
const int inv3 = (mod + 1) / 3;
const int inv6 = 1ll * inv2 * inv3 % mod;

unordered_map < ll, int > sl, sr, tot, slr;

void calc(ll x) {
	if(x == 1) return sl[x] = sr[x] = slr[x] = tot[x] = 1, void();
	if(sl.count(x)) return;
	ll ls = (x + 1) >> 1, rs = x - ls;
	calc(ls); calc(rs);
	sl[x] = (sl[ls] + sl[rs] + 1ll * tot[rs] * (ls % mod) % mod + 1) % mod;
	sr[x] = (sr[ls] + sr[rs] + 1ll * tot[rs] * (ls % mod) % mod + x % mod) % mod;
	slr[x] = (slr[ls] + slr[rs] + 1ll * (ls % mod) * (ls % mod) % mod * tot[rs] % mod + ls % mod * (sl[rs] + sr[rs]) % mod + x % mod) % mod;
	tot[x] = (tot[ls] + tot[rs] + 1) % mod;
}

ll s1(ll x) { x %= mod; return x * (x + 1) / 2 % mod; }
ll s2(ll x) { x %= mod; return x * (x + 1) % mod * (x * 2 + 1) % mod * inv6 % mod; }

ll n;

void solve() {
	n = in; calc(n);
	int ans = 2 * ((n + 1) % mod * s1(n) % mod - s2(n) + mod) % mod;
	ans = (ans - (n + 1) % mod * sl[n] % mod + slr[n] + mod) % mod;
	printf("%d\n", ans);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
	int T = in;
	while(T--) solve();
	return 0;
}
